﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;


public class GoldAndLv : MonoBehaviour
{
    public static GoldAndLv instance;
    public Text GoldText;
    public Text LvText;
    public AudioSource audio;
    public bool IsZhenDong;
    public Button GoShopButton;
    // Start is called before the first frame update
    void Start()
    {
        instance = this;
        GengXin();
        GoShopButton.onClick.AddListener(OnClickGoShopButton);
        JiaZaiResources();

    }
    public void JiaZaiResources()
    {
        GameObject obj = Instantiate(Resources.Load<GameObject>("Snow"));
        Destroy(obj, 2);
        GameObject obj1 = Instantiate(Resources.Load<GameObject>("GuangQuan"));
        Destroy(obj1, 2);
    }
    /// <summary>
    /// 更新金币信息
    /// </summary>
    public void GengXin()
    {
        if (DataManager.Instance.Gold >= 1000)
        {
            GoldText.text = ((DataManager.Instance.Gold / 1000) + (float)(DataManager.Instance.Gold % 1000) / 1000).ToString() + "k";
        }
        else
        {
            GoldText.text = (DataManager.Instance.Gold).ToString();
        }
        LvText.text = "LV."+(DataManager.Instance.Lv).ToString();

    }
    public void OnClickGoShopButton()
    {
        MainPanel.instance.OpenShangChengPanel();
    }

    /// <summary>
    /// 再次播放背景音乐
    /// </summary>
    public void PlayVoice()
    {
        audio.Play();
    }
}
